package at.codebase.core;

import at.codebase.security.SecureStringBuilder;

/**
 * @author Daniel Marth <danielmarth@gmx.at>
 */
public class LinkCreator {

	/*
	 * Item Links
	 */

	public static String itemLink(final Long itemId) {
		return itemLink(itemId, false);
	}

	public static String itemLink(Long itemId, boolean targetBlank) {
		return itemLink(itemId, itemId.toString(), targetBlank);
	}

	public static String itemLink(Long itemId, String itemTitle) {
		return itemLink(itemId, itemTitle, false);
	}

	public static String itemLink(Long itemId, String itemTitle,
			boolean targetBlank) {
		return new SecureStringBuilder()
				.appendInsecure(
						"<a " + (targetBlank ? "target=\"_blank\"" : "")
								+ " href=\"").appendSecure("/item/")
				.appendSecure(itemId.toString()).appendInsecure("\">")
				.appendSecure(itemTitle).appendInsecure("</a>").toString();
	}

	public static String itemLinkInsecure(Long itemId, String itemTitle) {
		return new SecureStringBuilder().appendInsecure("<a href=\"")
				.appendSecure("/item/").appendSecure(itemId.toString())
				.appendInsecure("\">").appendInsecure(itemTitle)
				.appendInsecure("</a>").toString();
	}

	/*
	 * User Links
	 */

	public static String userLink(final Long userId) {
		return userLink(userId, false);
	}

	public static String userLink(final Long userId, boolean targetBlank) {
		return userLink(userId, userId.toString(), targetBlank);
	}

	public static String userLink(final Long userId, String username) {
		return userLink(userId, username, false);
	}

	public static String userLink(final Long userId, String username,
			boolean targetBlank) {
		return new SecureStringBuilder()
				.appendInsecure(
						"<a " + (targetBlank ? "target=\"_blank\"" : "")
								+ " href=\"").appendSecure("/user/" + userId)
				.appendInsecure("\">").appendSecure(username)
				.appendInsecure("</a>").toString();
	}

	/*
	 * VShop Links
	 */

	public static String vShopLink(final Long vShopId) {
		return vShopLink(vShopId, false);
	}

	public static String vShopLink(final Long vShopId, boolean targetBlank) {
		return new SecureStringBuilder()
				.appendInsecure(
						"<a " + (targetBlank ? "target=\"_blank\"" : "")
								+ " href=\"").appendSecure("/vshop/")
				.appendSecure(vShopId.toString()).appendInsecure("\">")
				.appendSecure(vShopId.toString()).appendInsecure("</a>")
				.toString();
	}

	/*
	 * ImageLinks
	 */

	public static String imageLink(Long imageId) {
		return imageLink(imageId, false);
	}

	public static String imageLink(Long imageId, boolean targetBlank) {
		return new SecureStringBuilder()
				.appendInsecure(
						"<a " + (targetBlank ? "target=\"_blank\"" : "")
								+ " href=\"")
				.appendSecure("/service/image?id=")
				.appendSecure(imageId.toString()).appendInsecure("\">")
				.appendSecure(imageId.toString()).appendInsecure("</a>")
				.toString();
	}

	public static String absoluteImageLink(Long imageId) {
		return new SecureStringBuilder()
				.appendInsecure(Settings.getServerAddress())
				.appendInsecure("/service/image?id=")
				.appendInsecure(imageId.toString()).toString();
	}

	public static String absoluteItemLink(Long itemId) {
		return new SecureStringBuilder()
				.appendInsecure(Settings.getServerAddress())
				.appendInsecure("/item/").appendInsecure(itemId.toString())
				.toString();
	}

}
